﻿using System;
using System.Collections.Generic;
using SdmxMl.Manager;
using SdmxMl.Structure;
using SdmxMl.Common;
using System.Text;

namespace SdmxDiff
{
    public class MultilangDiff
    {
        public string DiffComment
        {
            get
            {
                string cmt = string.Empty;
                if (LangList != null && LangList.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string lg in LangList)
                        if (sb.Length == 0)
                        {
                            sb.Append(lg);
                        }
                        else
                        {
                            sb.Append(',').Append(lg);
                        }
                    sb.Append(')');

                    cmt = ReportDiff.TextDiffersMark + sb.ToString();
                }
                return cmt;
            }
        }

        public List<string> LangList { get; set; }
        public bool HasDiff { get { return LangList.Count > 0; } }

        public MultilangDiff(MultiLang mlo, MultiLang mln)
        {
            Initialize(mlo, mln, new List<string>(LangSupport.SupportedLanguages));
        }

        public MultilangDiff(MultiLang mlo, MultiLang mln, List<string> targetLangList)
        {
            Initialize(mlo, mln, targetLangList);
        }
        public MultilangDiff(MultiLang mlo, MultiLang mln, string targetLg)
        {
            List<string> list = new List<string>(new string[] { targetLg });
            Initialize(mlo, mln, list);
        }

        private void Initialize(MultiLang mlo, MultiLang mln, List<string> TargetLangList)
        {
            LangList = new List<string>();
            foreach (string lg in TargetLangList)
            {
                if (mln.GetForLanguage(lg) != mlo.GetForLanguage(lg))
                    LangList.Add(lg);
            }
        }
    }
}
